//////////////////////////////////////////////////////////////////////
//  Jack McCaffery
//  11-10-2014
//////////////////////////////////////////////////////////////////////

#include "topicModel/boundedParameters.H"

#include <limits>
using namespace std;


template <class SC>
BoundedParameters<SC>::~BoundedParameters ()
{

}

template <class SC>
BoundedParameters<SC>::BoundedParameters () :
	ParameterGroup<SC> (),
	lowerBound (numeric_limits<SC>::min ()),
	upperBound (numeric_limits<SC>::max ())
{

}

template <class SC>
void BoundedParameters<SC>::applyGradient (
	FixedParameters<SC> const &gradient_, double rate_)
{
	if (this->data.rows () != gradient_.getData ().rows ())
		qFatal ("Gradient rows do not match parameter rows");

	if (this->data.cols () != gradient_.getData ().cols ())
		qFatal ("Gradient rows do not match parameter columns");

	this->data += rate_ * gradient_.getData ();

	if (lowerBound != numeric_limits<SC>::min ())
		this->data = this->data.cwiseMax (lowerBound);

	if (upperBound != numeric_limits<SC>::max ())
		this->data = this->data.cwiseMin (upperBound);
}


template class BoundedParameters<bool>;
template class BoundedParameters<short>;
template class BoundedParameters<unsigned short>;
template class BoundedParameters<int>;
template class BoundedParameters<unsigned int>;
template class BoundedParameters<float>;
template class BoundedParameters<double>;
